﻿using FHJFPro.Base;
using FHJFPro.UserInfos.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FHJFPro.UserInfos
{
    public class UserInfoService : FHJFProAppService, IUserInfoService
    {
        private readonly IUserInfoRepository _userInfoRepository;
        private readonly UserInfoManager _userInfoManager;
        public UserInfoService(IUserInfoRepository userInfoRepository, UserInfoManager userInfoManager)
        {
            _userInfoRepository = userInfoRepository;
            _userInfoManager = userInfoManager;
        }
        public async Task<ResponseResult<UserInfoDto>> CreateAsync(CreateUserInfoDto input)
        {
            var result = new ResponseResult<UserInfoDto>();
            var userinfo =await _userInfoManager.CreateAsync(input.UserName, input.Password, input.Gender, input.Description);
            await _userInfoRepository.InsertAsync(userinfo,true);
            result.IsSuccess(ObjectMapper.Map<UserInfo, UserInfoDto>(userinfo));
            return await Task.FromResult(result);
        }
    }
}
